<!--processed-->
<link rel="stylesheet" href="/views/resolution/statistics/reply/tmp.css">
<link rel="stylesheet" href="/src/component/date/datepicker.css">
<section id="reply">
    <div class="breadcrumb">
        <i class="back iconfont icon-fanhui1" id="back"></i>
        <span>Resolution</span>
        <span class="interval">/</span>
        <span>Statistics</span>
    </div>
    <div class="layout-processed feat-grid">
        <form id="form" action="" class="header">
            <div class="header-sort fx-row-s">
                <div data-val="" class="sort-list ml30"><a href="#resolution/statistics/site">Paypal投诉量统计</a></div>
                <div data-val="" class="sort-list ml30 active-sort"><a href="#resolution/statistics/reply">员工回复统计</a></div>
                <div data-val="" class="sort-list ml30"><a href="#resolution/statistics/same">新增量统计</a></div>
            </div>
            <div class="clearfix">
                <div class="header-item w15 date-box ml30 fl">
                    <div class="c-datepicker-date-editor  J-datepicker-range-day">
                        <i class="c-datepicker-range__icon kxiconfont icon-clock"></i>
                        <input placeholder="开始日期" name="start_date" class="c-datepicker-data-input only-date" value="">
                        <span class="c-datepicker-range-separator">-</span>
                        <input placeholder="结束日期" name="end_date" class="c-datepicker-data-input only-date" value="">
                    </div>
                </div>
                <div class="header-item fl ml20 mt3">
                    <button id="check" type="button" class="btn-e">查询</button>
                    <button id="export" type="button" class="btn-a ml20">导出</button>
                </div>
            </div>
        </form>
        <div class="data-box com-check">
            <table class="table-a table-fixed">
                <thead class="t-head">
                    <tr>
                        <th class="tc">序号</th>
                        <th>个人邮件ID</th>
                        <th>姓名</th>
                        <th data-name="inquiry_cnt"><span class="inquiry_cnt">Dispute回复量</span><i class="inquiry_cnt iconfont icon-xialaxuanzeicon"></i></th>
                        <th data-name="claim_cnt"><span class="claim_cnt">Claim回复量</span><i class="claim_cnt iconfont icon-xialaxuanzeicon"></i></th>
                        <th data-name="chargeback_cnt"><span class="chargeback_cnt">Chargeback回复量</span><i class="chargeback_cnt iconfont icon-xialaxuanzeicon"></i></th>
                        <th data-name="total_cnt"><span class="total_cnt">已处理总量</span><i class="total_cnt iconfont icon-xialaxuanzeicon"></i></th>
                        <th><span class="detail">详情</span></th>
                    </tr>
                    <tr class="thead-fixed" data-name="replyCount">

                    </tr>
                </thead>
                <!--<tbody class="total-style" data-name="replyCount"></tbody>-->
                <tbody data-name="replyData">
                </tbody>
            </table>
        </div>

    </div>
    <footer class="footer fx-row-b">
        <div>
            <span>Showing <span id="page-start">1</span> to <span id="page-end">20</span> of <span id="page-total">0</span> entries</span>
            <select name="page">
                <option value="10">10</option>
                <option value="20">20</option>
                <option value="30">30</option>
                <option value="50">50</option>
                <option value="100">100</option>
            </select>
            <span>records per page</span>
        </div>
        <section id="box-page"></section>
    </footer>
</section>

<!--渲染模板开始-->

<!--list data-->
<script id="reply-data" type="text/html">
    {{each detail as v i}}
        <tr class="nth">
            <td class="tc"><span>{{i + $imports.count}}</span></td>
            <td>{{v.email_cs_admin_id}}</td>
            <td>{{v.customer_servicer}}</td>
            <td>{{v.inquiry_cnt}}</td>
            <td>{{v.claim_cnt}}</td>
            <td>{{v.chargeback_cnt}}</td>
            <td>{{v.total_cnt}}</td>
            <td>
                <a class="detail" href="/{{$imports.path}}#resolution/statistics/reply/detail/{{v.email_cs_admin_id}}" target="_self">
                    <button class="btn-d">查看</button>
                </a>
            </td>
        </tr>
    {{/each}}
</script>

<script id="reply-count" type="text/html">

        <td>合计(数量)</td>
        <td>{{employee_cnt}}</td>
        <td>/</td>
        <td>{{inquiry_cnt}}</td>
        <td>{{claim_cnt}}</td>
        <td>{{chargeback_cnt}}</td>
        <td>{{reply_cnt}}</td>
        <td>/</td>

</script>


<!-- js -->
<script>

    $.extend(window.p,{
        page:1,
        num:20,
        total:0,
        pageObj:null,
        src : [
            "/src/component/date/moment.min.js",
            "/src/component/date/datepicker.all.js",
        ],
        data:{
            inquiry_cnt:'asc',
            claim_cnt:'asc',
            chargeback_cnt:'asc',
            total_cnt:'desc',

            order: '',
            sort: ''
        },
    });

    $(function(){

        init();

        function init(){

            if(com.getCookie('pageNum')) {
                p.num = com.getCookie("pageNum");
            }

            //默认分页显示
            $("select[name='page']").val(p.num);
            //返回
            $(".back").click(function(){
                window.history.go(-1);
            });

            //初始化分页
            initPage();

            //选择分页事件
            $("select[name='page']").on('change',function(){
                var val = $(this).val();
                com.setCookie('pageNum',val,720);
                p.num = val;
                request();
                //location.reload();
            });

            //排序事件
            $(".inquiry_cnt").on('click',function(){
                sortTrigger($(this))
            });
            //排序事件
            $(".claim_cnt").on('click',function(){
                sortTrigger($(this))
            });
            //排序事件
            $(".chargeback_cnt").on('click',function(){
                sortTrigger($(this));
            });
            //排序事件
            $(".total_cnt").on('click',function(){
                sortTrigger($(this))
            });


            $("[data-name='replyData']").on('click','.detail',function(e){
                var start = $("input[name='start_date']").val();
                var end = $("input[name='end_date']").val();
                if(start&&end){
                    //para.tmpObj['start_date'] = start;
                    //para.tmpObj['end_date'] = end;

                    com.setCookie('start_date',start,30*24);
                    com.setCookie('end_date',end,30*24);
                }else{
                    e.preventDefault()
                }
            });

            //导出
            $("#export").on('click',function(){
                var start = $("input[name='start_date']").val();
                var end = $("input[name='end_date']").val();
                window.open(app.api('/api/exportEmployeeReplySts/'+start+'/' + end),'_blank');
            })

            $("#check").on('click',function(){
                request('init');
            });

            //初始化日期组件(js暂时插入当前页面模块 / 后期处理性能问题【2】)
            app.dynamicLoadJs(p.src,'reply',function(){
                $('.J-datepicker-range-day').datePicker({
                    hasShortcut: true,
                    format: 'YYYY-MM-DD',
                    isRange: true,
                    shortcutOptions: [
                        {
                            name: '今天',
                            day: '0,0'
                        },
                        {
                            name: '昨天',
                            day: '-1,0'
                        },
                        {
                        name: '最近一周',
                        day: '-7,0'
                    }, {
                        name: '最近一个月',
                        day: '-30,0'
                    }]
                });
                setTime();
                //初始化请求数据列表
                request();
            });

            //自动偏移thead
            /*$(".data-box").scroll(function(){
                var top = $(this).scrollTop();
                var theadObj = $(this).find('thead').eq(0);
                if(top > 1){
                    theadObj.css({'transform':'translateY('+ top +'px)'});
                } else{
                    theadObj.css({'transform':'translateY(0px)'});
                }
            })*/

        }

        function initPage(){
            p.pageObj = $("#box-page").comPage({
                total:p.total,
                pages:p.num,
                callback:function(page){
                    p.page = page;
                    request();
                }
            });
        }

        function renderLeftPage(){
            $("#page-total").html(p.total);
            $("#page-start").html((p.page-1)*p.num + 1);
            if(p.page === 1){
                $("#page-end").html(p.num);
            }else if(p.page == Math.ceil(p.total/p.num)) {
                $("#page-end").html(p.total);
            }else{
                $("#page-end").html(p.page*p.num);
            }
        }

        //请求列表
        function request(init){

            init && (p.page = 1);

            var loadObj = null;
            app.ajax({
                type:'post',
                url:app.api('/api/employeeReplySts'),
                data:getPara(),
                beforeSend:function(){
                    loadObj = $.load({
                        insert:$(".layout-processed"),
                    });
                    $('footer').removeClass('hide')
                },
                success:function(res){
                    template.defaults.imports.count = (p.page-1)*p.num + 1;
                    if(res.code == 0){
                        console.log(res)
                        var tmp = template('reply-data', res.data);
                        $("[data-name='replyData']").html(tmp);

                        var tmpTotal = template('reply-count',res.data.combine);
                        $("[data-name='replyCount']").html(tmpTotal);

                        p.total = res.data.total_cnt;
                        if(init){
                            p.pageObj.setPage(p.total,p.num,1);
                        }else{
                            p.pageObj.setPage(p.total,p.num);
                        }
                        renderLeftPage();

                    }else{
                        $.comMessage({
                            type:'warning',
                            text:res.msg,
                        });
                        $("[data-name='replyData']").html('');
                        $('footer').addClass('hide')
                    }
                },
                complete:function(){
                    loadObj.close()
                }
            });
        }


        //获取列表参数
        function getPara(){
            $.each($("#form").serializeArray(),function(index,item){
                p.data[item.name] = item.value ;
            });
            p.data.page = p.page;
            p.data.page_nums = p.num;
            return p.data;
        }

        function setTime(){
            var t = new Date().getTime();
            var oldTime = t - 86400*7*1000;
            var start = com.formatDate(oldTime,'-').split(' ')[0];
            var end = com.formatDate(t,'-').split(' ')[0];
            $("input[name='start_date']").val(end);
            $("input[name='end_date']").val(end);
        }

        //排序筛选
        function sortTrigger(obj){
            var name = obj.closest('th').attr('data-name');
            p.data[name] == 'asc' ? p.data[name] = 'desc' : p.data[name] = 'asc';
            p.data.sort = p.data[name];
            p.data.order = name;
            request();
        }

    })


</script>